<?php

use J\Schema\Syntax;

return [
    // 模型实体配置信息
    Syntax::KEY_COLLECTIONS => [
        // 用户登录信息
        'user' => [
            Syntax::KEY_ELEMENTS => [
                'name'     => [
                    Syntax::KEY_TYPE   => Syntax::VALUE_STRING | Syntax::MASK_MUST,
                    'length' => 100,
                    'label'  => '用户名',
                    'width'  => 200
                ],
                'nickname' => [
                    Syntax::KEY_TYPE   => Syntax::VALUE_STRING,
                    'length' => 100,
                    'label'  => '昵称',
                    'column' => 'nickname',
                    'width'  => 200
                ],
                'password' => [
                    Syntax::KEY_TYPE    => Syntax::VALUE_STRING | Syntax::MASK_MUST,
                    'holder'  => 'password',
                    'length'  => 64,
                    'label'   => '密码',
                    'align'   => 'left',
                ],
                'create_time' => [
                    Syntax::KEY_TYPE => Syntax::FIELD_DATE,
                    'label' => '注册时间',
                    'column' => 'reg_time',
                    'width'  => 150
                ],
                'update_time' => [
                    Syntax::KEY_TYPE => Syntax::FIELD_DATE,
                    'label' => '更新时间',
                    'column' => 'update_time',
                    'width'  => 150
                ],
                'last_time' => [
                    Syntax::KEY_TYPE => Syntax::FIELD_DATE,
                    'label' => '最后登录时间',
                    'column' => 'last_login_time',
                    'width'  => 150
                ],
                'ip' => [
                    Syntax::KEY_TYPE    => Syntax::VALUE_IP,
                    'label' => '注册Ip',
                    'column' => 'reg_ip',
                    'width'  => 150
                ],
                'last_ip' => [
                    Syntax::KEY_TYPE    => Syntax::VALUE_IP,
                    'label' => '最后登录IP',
                    'column' => 'last_login_ip',
                    'width'  => 150
                ]
            ],

            'table' => 'admin',

            #  实体标签
            'label' => '用户',
            #  实体默认显示域（比如文章实体默认显示 ）
            'key' => 'name',
        ],
        // 用户个人信息
        'member' => [
            Syntax::KEY_ELEMENTS => [
                'qq' => [
                    Syntax::KEY_TYPE   => Syntax::VALUE_STRING,
                    'length' => 20,
                    'label' => 'QQ',
                ],
                'birthday' => [
                    Syntax::KEY_TYPE   => Syntax::FIELD_DATE,
                    'label' => '生日',
                ],
                'sex' => [
                    Syntax::KEY_TYPE  => Syntax::VALUE_INT,
                    'display' => function ($v) {
                        return $v > 0 ? '男' : '女';
                    },
                    'label' => '性别'
                ],
                'score' => [
                    Syntax::KEY_TYPE  => Syntax::VALUE_INT,
                    'label' => '积分'
                ],
            ],
            'table' => 'member',
            #  实体标签
            'label' => '用户',
            #  实体默认显示域（比如文章实体默认显示 ）
            'key' => 'name',
        ],
        // 角色信息
        'role' => [
            Syntax::KEY_ELEMENTS => [
                'title' => [
                    Syntax::KEY_TYPE   => Syntax::VALUE_STRING,
                    'label'  => '角色名',
                    'length' => 100,
                    'width'  => 300
                ],
                'description' => [
                    Syntax::KEY_TYPE    => Syntax::VALUE_TEXT,
                    'label'   => '描述',
                    'align'   => 'left',
                    'width'   => 500
                ],
                'use_department'  =>[
                    'base'     =>'switch',
                    'label'    => '部门授权',
                    'column'   => 'use_department',
                    'width' => 50,
                    'default' => 0
                ]
            ],
            'label'   => '角色',
            'key'     => 'title'
        ],
        // 用户角色表
        'user_role' => [
            'table' => 'access',
            Syntax::KEY_ELEMENTS => [
                'role' => [
                    Syntax::KEY_TYPE => Syntax::FIELD_BLS,
                    'connectionMask' => 100,
                ],
                'user' => [
                    Syntax::KEY_TYPE => Syntax::FIELD_BLS,
                    'connectionMask' => 1000,
                ]
            ],
            #  实体标签
            'label' => '用户角色',
        ],
        // 资源信息表
        'resource' => [
            'table' => 'resource',
            Syntax::KEY_ELEMENTS => [
                'title' => [
                    Syntax::KEY_TYPE   => Syntax::VALUE_STRING,
                    'length'  => 200,
                    'label' => '名称',
                    'align' => 'left',
                    'width' => 200
                ],
                'resource' => [
                    Syntax::KEY_TYPE   => Syntax::FIELD_BLS,
                    'label'  => '上级菜单',
                    'default' => 0

                ],
                'sort' => [
                    Syntax::KEY_TYPE  => Syntax::VALUE_INT,
                    'label' => '排序',
                    'width'  => 50,
                    'default' => 0,
                ],
                'url' => [
                    Syntax::KEY_TYPE   => Syntax::VALUE_STRING,
                    'length'  => 200,
                    'width'  => 300,

                ],
                'tip' => [
                    Syntax::KEY_TYPE   => Syntax::VALUE_STRING,
                    'length' => 60,
                    'label'  => '权限说明',
                    'width'  => 500,
                ],
                'file' => [
                    Syntax::KEY_TYPE => Syntax::VALUE_STRING,
                    'length' => 200,
                    'width' => 300,
                    'default' => null,
                ],
            ],
            #  实体标签
            'label' => '资源',
            #  实体默认显示域（比如文章实体默认显示 ）
            'key' => 'title',
        ],
        // 角色资源表
        'resource_role' => [
            'table' => 'power',
            Syntax::KEY_ELEMENTS => [
                'role' => [
                    Syntax::KEY_TYPE => Syntax::FIELD_BLS
                ],
                'resource' => [
                    Syntax::KEY_TYPE    => Syntax::FIELD_BLS,
                    'column'  => 'operator'
                ]
            ],
            #  实体标签
            'label' => '角色权限',
        ],
        // 部门表
        'category' => [
            'table' => 'category',
            Syntax::KEY_ELEMENTS => [
                'title' => [
                    Syntax::KEY_TYPE   => Syntax::VALUE_STRING,
                    'length'  => 200,
                    'label' => '标题',
                    'align' => 'left',
                    'width' => 200,
                ],
                'category' => [
                    Syntax::KEY_TYPE => Syntax::VALUE_INT,
                    'label' => '上级栏目',
                    'column' => 'pid'
                ],

            ],
            'label'   => '部门',
            'key' => 'title',
            Syntax::KEY_TREE => 'category'
        ],
        // 用户部门表
        'user_category' => [
            'table' => 'home',
            Syntax::KEY_ELEMENTS => [
                'user'  => [
                    Syntax::KEY_TYPE => Syntax::FIELD_BLS,
                    'connectionMask' => 100,
                ],
                'category' => [
                    Syntax::KEY_TYPE => Syntax::FIELD_BLS,
                    'connectionMask' => 1000,
                ]
            ],
        ]
    ],
    // 控制器配置信息
    Syntax::KEY_CONTROLLERS => [
        // 用户管理
        'user' => [
            'title' => '用户管理',
            Syntax::KEY_OPTIONS => [
                'index' => [
                    'view' => Syntax::DISPLAY_TABLE,
                    Syntax::KEY_ELEMENTS => ['name', 'nickname', 'last_ip', 'last_time'],
                    'sort' => ['name'],
                    'search' => [
                        Syntax::KEY_ELEMENTS => ['nickname' => Syntax::OPERATOR_LIKE]
                    ],
                    'btns' => [
                        'items' => ['add' => [], 'deleteSelected' => []]
                    ],
                    'actions' => [
                        'items' => [
                            'edit' => [],
                            'delete' => [],
                            'bind' => [
                                'label' => '绑定',
                                'next' => '/element.php/UserCenter/Role/Bind'
                            ],
                            'one' => [
                                'label' => '部门',
                                'next' => '/element.php/UserCenter/category/one'
                            ],
                        ],
                    ],
                ],
                // 指定角色包含的用户列表
                'role' => [
                    'view' => Syntax::DISPLAY_TABLE,
                    Syntax::KEY_ELEMENTS => ['name', 'nickname'],
                    'sort' => ['name'],
                    'search' => [
                        Syntax::KEY_ELEMENTS => ['nickname' => Syntax::OPERATOR_LIKE]
                    ],
                    'dnib' => 'role',
                    // dataUrl
                    Syntax::KEY_QUERY => 'role',
                    'actions' => [
                        'items' => [
                            'Dnib' => [
                                'label' => '解绑',
                                Syntax::KEY_QUERY => 'role',
                            ],
                        ],
                    ],
                ],
                'add' => [
                    'view' => Syntax::DISPLAY_FORM,
                    Syntax::KEY_ELEMENTS => ['name', 'nickname', 'password'],
                ],
                'edit' => [
                    'view' => Syntax::DISPLAY_FORM,
                    'row' => true,
                    // 'where' => [Syntax::KEY_ID],
                    Syntax::KEY_ELEMENTS => ['name', 'nickname']
                ],
                'delete' => [],
            ]
        ],
        // 用户个人信息
        'member' => [
        ],
        // 角色管理
        'role' => [
            'title' => '角色管理',
            Syntax::KEY_OPTIONS => [
                'index'   => [
                    'view' => Syntax::DISPLAY_TABLE,
                    Syntax::KEY_ELEMENTS => ['title', 'description'],
                    'search' => [
                        Syntax::KEY_ELEMENTS => ['title' => Syntax::OPERATOR_LIKE]
                    ],
                    'btns' => ['items' => ['add' => [], 'deleteSelected' => []]],
                    'actions' => [
                        'items' => [
                            'edit' => [],
                            'delete' => [],
                            'power' => [
                                'label' => '授权',
                                'next' => '/element.php/UserCenter/Resource/Power'
                            ],
                            'role' => [
                                'label' => '用户',
                                'next' => '/element.php/UserCenter/User/Role',
                            ],
                        ],
                    ],
                ],
                'add'     => [
                    'view' => Syntax::DISPLAY_FORM,
                    Syntax::KEY_ELEMENTS => ['title', 'description',]
                ],
                'edit'    => [
                    'view' => Syntax::DISPLAY_FORM,
                    'row' => true,
                    Syntax::KEY_ELEMENTS => ['title', 'description',]
                ],
                // 指定用户的角色信息
                'bind' => [
                    'view' => Syntax::DISPLAY_TABLE,
                    Syntax::KEY_ELEMENTS => ['title', 'description'],
                    //
                    'many' => 'user',
                    // 生成 dataUrl
                    Syntax::KEY_QUERY => 'user',
                    'btns' => [
                        'items' => [
                            'bind' => [
                                'label' => '绑定',
                                'multiSelect' => true,
                                Syntax::KEY_QUERY => 'user',
                                'after' => ['controller' => 'user', 'action' => 'index']
                            ]
                        ]
                    ],
                ],
                'delete' => []
            ]
        ],
        // 资源管理
        'resource' => [
            'title' => '资源管理',
            Syntax::KEY_OPTIONS => [
                'index'   => [
                    'view' => Syntax::DISPLAY_TREE,
                    Syntax::KEY_ELEMENTS => ['title', 'tip', 'file', 'url'],
                    'btns' => ['items' => ['add' => []]],
                    'actions' => ['items' => [
                        'edit' => [],
                        'delete' => [],
                        'append' => [
                            'label' => '扩展',
                            'next' => ['action' => 'append'],
                        ],
                    ]]
                ],
                'add'     => [
                    'view' => Syntax::DISPLAY_FORM,
                    Syntax::KEY_ELEMENTS => ['title', 'tip', 'file', 'url', 'sort']
                ],
                'append'  => [
                    'view' => Syntax::DISPLAY_FORM,
                    'append' => true,
                    // 为创建API
                    Syntax::KEY_QUERY => true,
                    Syntax::KEY_ELEMENTS => ['title', 'tip', 'file', 'url', 'sort'],
                ],
                'edit'    => [
                    'view' => Syntax::DISPLAY_FORM,
                    'row' => true,
                    Syntax::KEY_ELEMENTS => ['title', 'tip', 'file', 'url', 'sort']
                ],
                // 角色的授权
                'power'   => [
                    'view' => Syntax::DISPLAY_SELECT,
                    Syntax::KEY_ELEMENTS => ['title', 'tip'],
                    'many' => 'role',
                    Syntax::KEY_TREE => true,
                    Syntax::KEY_QUERY => 'role',
                    'after' => '/element.php/UserCenter/role/index',
                ],
                'delete' => []
            ]
        ],
        // 部门管理
        'category' => [
            'title' => '部门管理',
            Syntax::KEY_OPTIONS => [
                // 用户的部门授权
                'one' => [
                    'view' => Syntax::DISPLAY_TABLE,
                    Syntax::KEY_ELEMENTS => ['title'],
                    'size' => -1,
                    'many' => 'user',
                    'btns' => ['items' => [
                        'one' => [
                            'label' => '授权',
                            'multiSelect' => true,
                            Syntax::KEY_QUERY => 'user',
                            'next' => ['controller' => 'user', 'action' => 'index']
                        ]
                    ]]
                ]
            ]
        ]
    ],
    // 安装信息
    Syntax::KEY_INSTALL => [
        'next' => 'UserCenter/User/Add',
        'values' => [
            'resource' => [
                [
                    'title' => '用户权限系统',
                    'resource' => 0,
                    'tip' => '用户权限信息',
                    'status' => 1
                ],
                [
                    'title' => '用户管理',
                    'resource' => 1,
                    'url' => '/UserCenter/User/Index',
                    'tip' => '用户信息管理',
                    'status' => 1
                ],
                [
                    'title' => '角色管理',
                    'resource' => 1,
                    'url' => '/UserCenter/Role/Index',
                    'tip' => '用户角色管理',
                    'status' => 1
                ],
                [
                    'title' => '资源管理',
                    'resource' => 1,
                    'url' => '/UserCenter/Resource/Index',
                    'tip' => '资源管理',
                    'status' => 1
                ],
                [
                    'title' => '功能测试',
                    'resource' => 0,
                    'tip' => '随机生成测试数据',
                    'status' => 1
                ],
                [
                    'title' => '用户数据',
                    'resource' => 5,
                    'url' => '/UserCenter/Mock/User',
                    'tip' => '随机生成用户数据',
                    'status' => 1,
                    'file' => '/api.php'
                ],
                [
                    'title' => '角色数据',
                    'resource' => 5,
                    'url' => '/UserCenter/Mock/Role',
                    'tip' => '随机生成角色数据',
                    'status' => 1,
                    'file' => '/api.php'
                ],
                [
                    'title' => '授权数据',
                    'resource' => 5,
                    'url' => '/UserCenter/Mock/Power',
                    'tip' => '随机生成角色数据',
                    'status' => 1,
                    'file' => '/api.php'
                ]
            ]
        ]
    ]
];

